#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=1e6+5,inf=1e18;
int n,m,C;
int a[Maxn],lsh[Maxn];


inline int calc(int i,int j){return (i<=j?lsh[j]-lsh[i]:C);}
namespace sub1{
	int f[2][Maxn];
	inline void solve(){
		memset(f,0x7f,sizeof f);
		f[0][m]=0;
		for(int i=1;i<=n;i++){
			int suf=inf;
			for(int j=m;j;j--)suf=min(suf,f[i&1^1][j]),f[i&1][j]=suf+calc(a[i],j);
		}int res=inf;
		for(int j=m;j;j--)res=min(res,f[n&1][j]);
		printf("%lld\n",res);
	}
}

signed main(){
	freopen("minimize.in","r",stdin);
	freopen("minimize.out","w",stdout);
	n=read();C=read();
	for(int i=1;i<=n;i++)lsh[i]=a[i]=read();
	if(!C)puts("0"),exit(0);
	sort(lsh+1,lsh+1+n);
	m=unique(lsh+1,lsh+1+n)-lsh-1;
	for(int i=1;i<=n;i++)a[i]=lower_bound(lsh+1,lsh+1+m,a[i])-lsh;
	sub1::solve(),exit(0);
	return 0;
}

